﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace OverlakeApp.Views
{
    /// <summary>
    /// A page that displays the current user's assembled schedule, with blocks.
    /// </summary>
    public partial class ViewSchedulePage : PhoneApplicationPage
    {
        private ViewModels.OverlakeViewModel vm;

        /// <summary>
        /// Initializes the ViewSchedulePage
        /// </summary>
        public ViewSchedulePage()
        {
            InitializeComponent();
            vm = this.DataContext as ViewModels.OverlakeViewModel;
        }

        private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                string id = (e.AddedItems[0] as AppService.ScheduleLine).SectionID;
                vm.CurrentSection = vm.Sections.First(s => s.SectionID == id);
                NavigationService.Navigate(new Uri("/Views/ViewCoursePage.xaml", UriKind.Relative));

                (sender as ListBox).SelectedItem = null;
            }
        }
    }
}